package org.jpa;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.jpa.dto.UserDetails;

public class JPATest {
	
	private static final String PERSISTENCE_UNIT_NAME = "jpaExample";
	private static EntityManagerFactory factory;
	
	public static void main(String[] arg){	
		JPATest jpaTest = new JPATest();
		EntityManager entityManager = jpaTest.getEntityManager();
		entityManager.getTransaction().begin();
		UserDetails userDetails1 = new UserDetails();
		userDetails1.setUserId(1);
		userDetails1.setUserName("First User");
		entityManager.persist(userDetails1);
		entityManager.getTransaction().commit();
		
	}
	
	private EntityManager getEntityManager(){
		factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
	    return factory.createEntityManager();
	}

}
